package com.link2room.rodimus.controller.manager;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.sideswipe.permissionResouces.annotation.L2RPermissionResources;
import com.link2room.rodimus.dto.param.base.MemberBaseDto;
import com.link2room.rodimus.dto.param.manager.MemberManagerParamDto;
import com.link2room.rodimus.facade.IMemberManagerFacadeService;
import com.link2room.soundwave.dto.param.inside.MemberLoginInsideParamDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.link2room.rodimus.constant.PermissionConstant.*;


/**
 * Created by VegetaKo on 2016/11/9.
 */
@Api(tags = "会员相关")
@RestController
@RequestMapping("/manager/Member")
public class MemberManagerController {

    @Resource
    private IMemberManagerFacadeService memberManagerFacadeService;

    @ApiOperation(value = "会员列表", response = MemberBaseDto.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="lhotelCode",value = "酒店代码", required = false),
            @ApiImplicitParam(name="memberNo",value = "会员号", required = false),
            @ApiImplicitParam(name="memberName",value = "会员姓名", required = false),
            @ApiImplicitParam(name="memberName",value = "会员姓名", required = false),
    })
    @RequestMapping(method = RequestMethod.GET)
    @L2RPermissionResources(value = member, name = "会员详情")
    public BaseResultDto GetMember(
                                   @RequestParam(name = "lhotelCode", required = false) String lhotelCode,
                                   @RequestParam(name = "memberNo", required = false) String memberNo,
                                   @RequestParam(name = "memberName", required = false) String memberName,
                                   @RequestParam(name = "currentPage", required = false) Integer currentPage,
                                   @RequestParam(name = "pageSize", required = false) Integer pageSize,
                                   @RequestParam(name = "sta", required = true) String sta) throws Exception {
        BaseResultDto res = new BaseResultDto();
        MemberManagerParamDto memberManagerParamDto = new MemberManagerParamDto();
        memberManagerParamDto.setLhotelCode(lhotelCode);
        memberManagerParamDto.setMemberNo(memberNo);
        memberManagerParamDto.setMemberName(memberName);
        memberManagerParamDto.setPageSize(pageSize);
        memberManagerParamDto.setCurrentPage(currentPage);
        res.setResultCode(0);
        // res.setQueryResult(salesmaManagerFacadeService.listSalesman(salesmanParamDto ) );
        return res;
    }

    @ApiOperation(value = "会员同步")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="lhotelCode",value = "酒店代码", required = false),
            @ApiImplicitParam(name="memberNo",value = "会员号", required = false),
            @ApiImplicitParam(name="memberName",value = "会员姓名", required = false),
    })
    @RequestMapping("/SyncAll")
    @L2RPermissionResources(value = memberSyncAll, name="全量会员信息同步")
    public BaseResultDto syncMember(
                                    @RequestParam(name = "lhotelCode", required = false) String lhotelCode,
                                    @RequestParam(name = "memberNo", required = false) String memberNo,
                                    @RequestParam(name = "memberName", required = false) String memberName,
                                    @RequestParam(name = "currentPage", required = false) Integer currentPage,
                                    @RequestParam(name = "pageSize", required = false) Integer pageSize) throws Exception {
        BaseResultDto res = new BaseResultDto();
        MemberLoginInsideParamDto memberLoginParamDto = new MemberLoginInsideParamDto();
        memberLoginParamDto.setPageSize(pageSize);
        memberLoginParamDto.setCurrentPage(currentPage);
        res.setResultCode(0);
        memberManagerFacadeService.bindingPMSMemberAll(memberLoginParamDto);
        return res;
    }

    @ApiOperation(value = "会员解绑")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="lhotelCode",value = "酒店代码", required = false),
            @ApiImplicitParam(name="memberNo",value = "会员号", required = false),
            @ApiImplicitParam(name="memberName",value = "会员姓名", required = false),
    })
    @RequestMapping("/Unbind")
    @L2RPermissionResources(value = memberUnbind, name="会员解绑pms")
    public BaseResultDto unbind(
            @RequestParam(name = "lhotelCode", required = false) String lhotelCode,
            @RequestParam(name = "memberNo", required = false) String memberNo,
            @RequestParam(name = "memberName", required = false) String memberName) throws Exception {
        BaseResultDto res = new BaseResultDto();
        MemberManagerParamDto memberManagerParamDto = new MemberManagerParamDto();
        memberManagerParamDto.setLhotelCode(lhotelCode);
        memberManagerParamDto.setMemberName(memberName);
        memberManagerParamDto.setMemberNo(memberNo);
        res.setResultCode(0);
        memberManagerFacadeService.unbindMemberInfo(memberManagerParamDto);
        return res;
    }
}
